package net.zjitc.jdbc;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/24 10:46
 */
public class PreparedStatementTest2 {
    public static void main(String[] args) {
        Scanner scannerStr=new Scanner(System.in);
        Scanner scannerInt=new Scanner(System.in);
        Connection conn=null;
        PreparedStatement pstmt=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/hxy";
            String user="root";
            String password="123456";
            conn= DriverManager.getConnection(url,user,password);
            String sql="DELETE FROM USER WHERE NAME=? and age=? ";
            pstmt = conn.prepareStatement(sql);
            System.out.println("请输入要删除的用户名：");
            String name=scannerStr.nextLine();
            System.out.println("请输入要删除的年龄：");
            int age=scannerInt.nextInt();
            pstmt.setString(1,name);
            pstmt.setInt(2,age);

            int c=pstmt.executeUpdate();
            System.out.println("影响了"+c+"行");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
